//
//  WordTestOldDataAlertView.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/7/7.
//

#import "WordTestOldDataAlertView.h"

@interface WordTestOldDataAlertView()

@property(nonatomic,strong)UILabel *courseLabel;
@property(nonatomic,strong)UILabel *precentLabel;
@property(nonatomic,strong)UIProgressView *progressView;

@end

@implementation WordTestOldDataAlertView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    __weak typeof(self)weakSelf = self;
    self.backgroundColor = UIColorHex_(0x000000,0.4);
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 10;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(@280);
        make.height.mas_equalTo(@164);
        make.centerX.mas_equalTo(weakSelf);
        make.centerY.mas_equalTo(weakSelf);
    }];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.font = JPUIFontPingFangSCMedium(16);
    titleLabel.textColor = KFontBlackColor;
    titleLabel.text = @"是否继续上次测试？";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [bgView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(@20);
        make.height.mas_equalTo(@22);
        make.left.mas_equalTo(@16);
        make.right.mas_equalTo(@-16);
    }];
    
    self.precentLabel = [[UILabel alloc]init];
    self.precentLabel.font = JPUIFontPingFangSCRegular(13);
    self.precentLabel.textColor = KFontGrayColor;
    self.precentLabel.textAlignment = NSTextAlignmentRight;
    [bgView addSubview:self.precentLabel];
    CGFloat p_w = [self getStringWidthWithText:self.precentLabel.text font:self.precentLabel.font viewHeight:18];
    [self.precentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(@-24);
        make.height.mas_equalTo(@18);
        make.width.mas_equalTo(p_w);
        make.top.mas_equalTo(@66);
    }];
    
    self.courseLabel = [[UILabel alloc]init];
    self.courseLabel.font = JPUIFontPingFangSCRegular(13);
    self.courseLabel.textColor = KFontGrayColor;
    [bgView addSubview:self.courseLabel];
    [self.courseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@24);
        make.height.mas_equalTo(@18);
        make.right.mas_equalTo(weakSelf.precentLabel.mas_left).offset(-16);
        make.top.mas_equalTo(@66);
    }];
    
    self.progressView = [[UIProgressView alloc]init];
    self.progressView.backgroundColor = KbgColor;
    self.progressView.layer.cornerRadius = 2;
    self.progressView.layer.masksToBounds = YES;
    self.progressView.trackTintColor = KbgColor;
    self.progressView.progressTintColor = KThemeColor;
    [bgView addSubview:self.progressView];
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.courseLabel.mas_bottom).offset(8);
        make.height.mas_equalTo(@4);
        make.left.mas_equalTo(@24);
        make.right.mas_equalTo(@-24);
    }];
    
    CGFloat b_w = (280-1)/2.0;
    
    UIButton *noBtn = [[UIButton alloc]init];
    [noBtn setTitle:@"否" forState:UIControlStateNormal];
    [noBtn setTitleColor:KFontGrayColor forState:UIControlStateNormal];
    noBtn.titleLabel.font  =JPUIFontPingFangSCRegular(16);
    [noBtn addTarget:self action:@selector(noBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:noBtn];
    [noBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(@0);
        make.width.mas_equalTo(b_w);
        make.height.mas_equalTo(@48);
    }];
    
    
    UIButton *yesBtn = [[UIButton alloc]init];
    [yesBtn setTitle:@"是" forState:UIControlStateNormal];
    [yesBtn setTitleColor:KThemeColor forState:UIControlStateNormal];
    yesBtn.titleLabel.font  =JPUIFontPingFangSCRegular(16);
    [yesBtn addTarget:self action:@selector(yesBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:yesBtn];
    [yesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(@0);
        make.width.mas_equalTo(b_w);
        make.height.mas_equalTo(@48);
    }];
    
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = KbgColor;
    [bgView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(@0);
        make.height.mas_equalTo(@0.5);
        make.bottom.mas_equalTo(@-48);
    }];
    
    UIView *line2 = [[UIView alloc]init];
    line2.backgroundColor = KbgColor;
    [bgView addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(@0);
        make.width.mas_equalTo(@0.5);
        make.centerX.mas_equalTo(bgView);
        make.height.mas_equalTo(@48);
    }];
    
    
}

-(void)noBtnClick{
    if(_clickBlock){
        _clickBlock(NO);
    }
}


-(void)yesBtnClick{
    if(_clickBlock){
        _clickBlock(YES);
    }
}

-(void)setModel:(LastCourseTestModel *)model{
    _model = model;
    self.courseLabel.text = model.courseName;
    self.precentLabel.text = [NSString stringWithFormat:@"%@%%",model.percent];
    self.progressView.progress = model.percent.floatValue/100.0;
    CGFloat p_w = [self getStringWidthWithText:self.precentLabel.text font:self.precentLabel.font viewHeight:18];
    [self.precentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(p_w);
    }];
    __weak typeof(self)weakSelf = self;
    [self.courseLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakSelf.precentLabel.mas_left).offset(-16);
    }];
}

@end
